<?php
    session_start();
    if(!isset($_SESSION['username'])){
        header("Location:Login.php");
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>成绩查询</title>
</head>
<body>
    <?php
        include_once "HeaderNav.html";  //引入头部
    ?>
    <h2>成绩查询</h2>    
    <form action="" method="post">
        请输入学号：<input type="text" name="studentid" /> <input type="submit" name="submit" value="查询">
    </form>
    <p></p>
    <?php
        if(isset($_POST['submit'])){  //点击登录按钮
            if($_POST['studentid']!=""){
                $studentid = $_POST['studentid'];
                //数据库查询判断
                require 'Conn.php';
                $sql = "SELECT student.StudentID,student.StudentName,course.CourseName,result.Mark FROM student".
                       " INNER JOIN result ON student.StudentID=result.StudentID INNER JOIN course ON course.CourseID=result.CourseID".
                       " WHERE student.StudentID='$studentid'";
                //echo $sql;
                //exit();
                $result = $db->query($sql);
                if(mysqli_num_rows($result)>0){
                    echo "<table class='tb'>";
                    while($rows = $result->fetch_assoc()){
                        echo "<tr>";
                        echo "<td>".$rows["StudentID"]."</td>";
                        echo "<td>".$rows["StudentName"]."</td>";
                        echo "<td>".$rows["CourseName"]."</td>";
                        echo "<td>".$rows["Mark"]."</td>";
                        echo "</tr>";
                    }
                    echo "</table>";
                }else{
                    echo "没有该学生成绩！";
                }
                $result->close();
                $db->close();
            }
        }
    ?>
    <?php
        include_once "Footer.html";  //引入脚部
    ?>
</body>
</html>